package com.softWang.common.constants;


import com.softWang.common.base.ExcelEnumCovertInterface;
import com.softWang.common.base.IntArrayValuable;
import lombok.Getter;

import java.util.Arrays;

/*
 * 通用状态枚举
 */
@Getter
public enum CommonStateEnum implements ExcelEnumCovertInterface, IntArrayValuable {

    /**
     * 正常
     */
    NORMAL(0,"正常"),
    /**
     * 停用
     */
    DISABLE(1,"停用");

    public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(CommonStateEnum::getCode).toArray();
    private Integer code;
    private String msg;

    CommonStateEnum(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public String getExcelLable(Integer value) {
        if (value == null) {
            return null;
        }
        CommonStateEnum commonState = null;
        for (CommonStateEnum state : values()) {
            if (state.getCode().equals(value)) {
                commonState = state;
                break;
            }
        }
        if (commonState == null) {
            return null;
        }
        return commonState.getMsg();
    }


    public Integer getJavaValue(String label) {
        if (label == null) {
            return null;
        }
        CommonStateEnum commonState = null;
        for (CommonStateEnum state : values()) {
            if (state.getMsg().equals(label)) {
                commonState = state;
                break;
            }
        }
        if (commonState == null) {
            return null;
        }
        return commonState.getCode();
    }

    @Override
    public int[] array() {
        return ARRAYS;
    }
}
